/**
 * 
 */
package com.google.code.sip.ucenter.dao.mongo;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.google.code.sip.core.dao.mongo.GenericMongoDao;
import com.google.code.sip.ucenter.dao.CreditDao;
import com.google.code.sip.ucenter.model.Credit;
import com.google.code.sip.ucenter.model.CreditType;
import com.google.code.sip.ucenter.model.User;

/**
 * @author Liuye
 * 
 */

public class CreditDaoImpl extends GenericMongoDao<Credit, String> implements
		CreditDao {
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.code.sip.ucenter.dao.mongo.CreditDao#findByUser(com.google.code
	 * .ucenter.model.User)
	 */
	public List<Credit> findByUser(User user) {
		return findByProperty("user", user);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.code.sip.ucenter.dao.mongo.CreditDao#get(com.google.code.sip.ucenter
	 * .model.User, com.google.code.sip.ucenter.model.CreditType)
	 */
	public Credit get(User user, CreditType creditType) {
		Map<String, Object> filters = new LinkedHashMap<String, Object>();
		filters.put("user", user);
		filters.put("creditType", creditType);
		return getByProperties(filters);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.code.sip.ucenter.dao.mongo.CreditDao#findByCreditType(com.google
	 * .code.ucenter.model.CreditType)
	 */
	public List<Credit> findByCreditType(CreditType creditType) {
		return findByProperty("creditType", creditType);
	}

}
